<html>
	<head>
		<script src="../gears_init.js"></script>
		<script src="../GearsORM.js"></script>
		<script src="../GearsORM.Events.js"></script>
		<script src="../GearsORM.ResultIterator.js"></script>
		<script src="../GearsORM.Sql.js"></script>
		<script src="../GearsORM.Fields.js"></script>
		<script src="../GearsORM.Model.js"></script>
		<script src="../GearsORM.Introspection.js"></script>
		<script src="../GearsORM.Transaction.js"></script>
		<script>
			GearsORM.dbName = "test.events";
			var Person = new GearsORM.Model({
				name:"Person",
				fields:
				{
					firstName:new GearsORM.Fields.String({maxLength:25}),
					lastName:new GearsORM.Fields.String({maxLength:25})
				}
			});
			
			var Tests =
			{
				up:function()
				{
					Person.dropTable();
					Person.createTable();
				},
				"test if model events works":function()
				{
					var flagSave = "",flagRemove = "";
					Person.addListener("onBeforeSave",function(){flagSave += "Before"});
					Person.addListener("onAfterSave",function(){flagSave += "After"});
					Person.addListener("onBeforeRemove",function(){flagRemove += "Before"});
					Person.addListener("onAfterRemove",function(){flagRemove += "After"});
					var someone = new Person();
					someone.firstName = "Jhon";
					someone.lastName = "Doe";
					someone.save();
					UnitTest.assertEqual("BeforeAfter",flagSave);
					someone.remove();
					UnitTest.assertEqual("BeforeAfter",flagRemove);
				},
				down:function()
				{
					Person.dropTable();
				}
			};
		</script>
		<script src="unit_test.js"></script>
	</head>
	<body>
		
	</body>
</html>